package com.shujia.source

import org.apache.flink.streaming.api.scala._

object Demo02FileSource {
  def main(args: Array[String]): Unit = {

    val env: StreamExecutionEnvironment = StreamExecutionEnvironment.getExecutionEnvironment

    // 将文件作为Source构建DataStream --> 有界流
    val stuDS: DataStream[String] = env.readTextFile("Flink/data/stu/students.txt")

    // 统计班级人数
    stuDS
      .map(line => (line.split(",")(4), 1))
      .keyBy(kv => kv._1)
      .sum(1)
      .print()

    env.execute()


  }

}
